package com.cardone.platform.authority.controller;

import java.util.List;
import java.util.concurrent.Callable;

import lombok.Setter;
import lombok.extern.slf4j.Slf4j;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.cardone.common.dto.PaginationDto;
import com.cardone.common.dto.ReturnDataDto;
import com.cardone.common.util.ReturnDataUtils;
import com.cardone.context.ContextHolder;
import com.cardone.platform.authority.dto.UsGroupOrgDto;
import com.cardone.platform.authority.service.UsGroupOrgService;

/**
 * 用户组与组织
 *
 * @author yaohaitao
 */
@Deprecated
@Setter
@Slf4j
@RequestMapping("/authority/usGroupOrg/")
@Controller
public class UsGroupOrgController {
	/**
	 * 初始化数据绑定
	 *
	 * @param webDataBinder
	 *          数据绑定
	 */
	// @InitBinder
	// @Deprecated
	// public void initBinder(final WebDataBinder webDataBinder) {
	// }

	/**
	 * 用户组与组织：删除
	 *
	 * @param deleteUsGroupOrg
	 *          用户组与组织对象
	 * @return 处理结果，json格式
	 */
	@Deprecated
	@RequestMapping(value = { "delete.json" }, method = RequestMethod.POST)
	@ResponseBody
	public Callable<ReturnDataDto<String>> deleteJson(final UsGroupOrgDto deleteUsGroupOrg) {
		return new Callable<ReturnDataDto<String>>() {
			@Override
			public ReturnDataDto<String> call() throws Exception {
				try {
					ContextHolder.getBean(UsGroupOrgService.class).deleteByIds(deleteUsGroupOrg);

					return ReturnDataUtils.newReturnData();
				} catch (final Exception e) {
					return ReturnDataUtils.newReturnData(e, UsGroupOrgController.log);
				}
			}
		};
	}

	/**
	 * 用户组与组织：分页查询
	 *
	 * @param findUsGroupOrg
	 *          用户组与组织对象
	 * @param model
	 *          上下文映射
	 */
	@Deprecated
	@RequestMapping(value = { "edit.html" })
	public void editHtml(final UsGroupOrgDto findUsGroupOrg, final Model model) {
		final UsGroupOrgDto usGroupOrg = ContextHolder.getBean(UsGroupOrgService.class).findById(UsGroupOrgDto.class, findUsGroupOrg);

		model.addAttribute("usGroupOrg", usGroupOrg);
	}

	/**
	 * 用户组与组织：编辑
	 *
	 * @param findUsGroupOrg
	 *          用户组与组织对象
	 * @return 实体对象集，json格式
	 */
	@Deprecated
	@RequestMapping(value = { "findById.json" })
	@ResponseBody
	public Callable<ReturnDataDto<UsGroupOrgDto>> findByIdJson(final UsGroupOrgDto findUsGroupOrg, final Model model) {
		return new Callable<ReturnDataDto<UsGroupOrgDto>>() {
			@Override
			public ReturnDataDto<UsGroupOrgDto> call() throws Exception {
				try {
					final UsGroupOrgDto usGroupOrg = ContextHolder.getBean(UsGroupOrgService.class).findById(UsGroupOrgDto.class, findUsGroupOrg);

					return ReturnDataUtils.newReturnData(usGroupOrg);
				} catch (final Exception e) {
					return ReturnDataUtils.newReturnData(e, UsGroupOrgController.log);
				}
			}
		};
	}

	/**
	 * 用户组与组织：查询
	 *
	 * @param findListUsGroupOrg
	 *          用户组与组织对象
	 * @return 用户组与组织对象集合，json格式
	 */
	@Deprecated
	@RequestMapping(value = { "findListByLikeCode.json" })
	@ResponseBody
	public Callable<ReturnDataDto<List<UsGroupOrgDto>>> findListByLikeCodeJson(final UsGroupOrgDto findListUsGroupOrg) {
		return new Callable<ReturnDataDto<List<UsGroupOrgDto>>>() {
			@Override
			public ReturnDataDto<List<UsGroupOrgDto>> call() throws Exception {
				try {
					final List<UsGroupOrgDto> usGroupOrgList = ContextHolder.getBean(UsGroupOrgService.class).findListByLikeCode(UsGroupOrgDto.class, findListUsGroupOrg);

					return ReturnDataUtils.newReturnData(usGroupOrgList);
				} catch (final Exception e) {
					return ReturnDataUtils.newReturnData(e, UsGroupOrgController.log);
				}
			}
		};
	}

	/**
	 * 用户组与组织：分页查询
	 *
	 * @param paginationUsGroupOrg
	 *          用户组与组织对象
	 * @return 分页，json格式
	 */
	@Deprecated
	@RequestMapping(value = { "paginationByLikeCode.json" })
	@ResponseBody
	public Callable<ReturnDataDto<PaginationDto<UsGroupOrgDto>>> paginationByLikeCodeJson(final UsGroupOrgDto paginationUsGroupOrg) {
		return new Callable<ReturnDataDto<PaginationDto<UsGroupOrgDto>>>() {
			@Override
			public ReturnDataDto<PaginationDto<UsGroupOrgDto>> call() throws Exception {
				try {
					final PaginationDto<UsGroupOrgDto> usGroupOrgPagination = ContextHolder.getBean(UsGroupOrgService.class).paginationByLikeCode(UsGroupOrgDto.class, paginationUsGroupOrg);

					return ReturnDataUtils.newReturnData(usGroupOrgPagination);
				} catch (final Exception e) {
					return ReturnDataUtils.newReturnData(e, UsGroupOrgController.log);
				}
			}
		};
	}

	/**
	 * 用户组与组织：分页查询
	 *
	 * @param paginationUsGroupOrg
	 *          用户组与组织对象
	 * @param model
	 *          上下文映射
	 */
	@Deprecated
	@RequestMapping(value = { "pagination.html" })
	public void paginationHtml(final UsGroupOrgDto paginationUsGroupOrg, final Model model) {
		final PaginationDto<UsGroupOrgDto> usGroupOrgPagination = ContextHolder.getBean(UsGroupOrgService.class).paginationByLikeCode(UsGroupOrgDto.class, paginationUsGroupOrg);

		model.addAttribute("usGroupOrgPagination", usGroupOrgPagination);
	}

	/**
	 * 用户组与组织：保存
	 *
	 * @param saveUsGroupOrg
	 *          用户组与组织对象
	 * @return 处理结果，json格式
	 */
	@Deprecated
	@RequestMapping(value = { "save.json" })
	@ResponseBody
	public Callable<ReturnDataDto<String>> saveJson(final UsGroupOrgDto saveUsGroupOrg) {
		return new Callable<ReturnDataDto<String>>() {
			@Override
			public ReturnDataDto<String> call() throws Exception {
				try {
					ContextHolder.getBean(UsGroupOrgService.class).saveByIdOrCode(UsGroupOrgDto.class, saveUsGroupOrg);

					return ReturnDataUtils.newReturnData();
				} catch (final Exception e) {
					return ReturnDataUtils.newReturnData(e, UsGroupOrgController.log);
				}
			}
		};
	}
}
